home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Science / RLaB / help / ode < prev    next >
Text File  |  1994-04-25  |  4KB  |  133 lines

  1. ode:
  2.  
  3. Syntax:    ode ( rhsf, ystart, tstart, tend, dtout, relerr, abserr )
  4.  
  5. Synopsis:       Integrate a system of first order differential
  6.             equations. 
  7.  
  8. Description:
  9.  
  10.         ode integrates a system of N first order ordinary
  11.     differential equations of the form: 
  12.  
  13.                 dy(i)/dt = f(t,y(1),y(2),...,y(N))
  14.                 y(i) given at  t .
  15.  
  16.         The arguments to ode are:
  17.  
  18.         rhsf    A function that evaluates dy(i)/dt at t. The function
  19.                 takes two arguments and returns dy/dt. An example that
  20.                 generates dy/dt for Van der Pol's equation is shown
  21.                 below. 
  22.  
  23.                 vdpol = function ( t , x ) 
  24.                 {
  25.                   local (xp)
  26.                   xp = zeros(2,1);
  27.                   xp[1] = x[1] * (1 - x[2]^2) - x[2];
  28.                   xp[2] = x[1];
  29.                   return xp;
  30.                 };
  31.  
  32.     ystart    The initial values of y, y(tstart).
  33.  
  34.         tstart  The initial value of the independent variable.
  35.  
  36.         tend    The final value of the independent variable.
  37.  
  38.         dtout   The output interval. The vector y will be saved at
  39.                 tstart, increments of tstart + dtout, and tend. If
  40.                 dtout is not specified, then the default is to store
  41.                 output at 101 values of the independent variable.
  42.  
  43.         relerr  The relative error tolerance. Default value is 1.e-6.
  44.  
  45.         abserr  The absolute error tolerance. At each step, ode
  46.                 requires that:
  47.  
  48.                 abs(local error) <= abs(y)*relerr + abserr
  49.                 
  50.                 For each component of the local error and solution
  51.                 vectors. The default value is 1.e-6.
  52.  
  53.  
  54.     The Fortran source code for ode() is completely explained and
  55.     documented in the text, "Computer Solution of Ordinary
  56.     Differential Equations: The Initial Value Problem" by 
  57.     L. F. Shampine and  M. K. Gordon.
  58.  
  59.     Example:
  60.  
  61.     //-----------------------------------------------------------//
  62.     //  Integrate the Van der Pol equation, and measure the effect
  63.     //  of relerr and abserr on the solution.
  64.     //
  65.     
  66.     vdpol = function ( t , x ) 
  67.     {
  68.       local (xp)
  69.       xp = zeros(2,1);
  70.       xp[1] = x[1] * (1 - x[2]^2) - x[2];
  71.       xp[2] = x[1];
  72.       return xp;
  73.     };
  74.     
  75.     t0 = 0;
  76.     tf = 10;
  77.     x0 = [0; 0.25];
  78.     dtout = 0.05;
  79.     
  80.     relerr = [1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1];
  81.     abserr = relerr;
  82.     
  83.     //
  84.     //  Baseline
  85.     //
  86.     
  87.     xbase = ode( vdpol, x0, 0, 20, 0.05, 1e-9, 1e-9);
  88.     results = zeros (relerr.n, abserr.n);
  89.     elapse = zeros (relerr.n, abserr.n);
  90.     
  91.     //
  92.     // Now loop through the combinations of relerr
  93.     // and abserr, saving the results, and computing
  94.     // the maximum difference.
  95.     //
  96.  
  97.     "start testing loop"
  98.     for (i in 1:abserr.n)
  99.     {
  100.       xode.[i] = <<>>;
  101.       for (j in 1:relerr.n)
  102.       {
  103.         printf("\t%i %i\n", i, j);
  104.         tic();
  105.         xode.[i].[j] = ode( vdpol, x0, 0, 20, 0.05, relerr[j], abserr[i]);
  106.         elapse[i;j] = toc();
  107.     
  108.         // Save results
  109.         results[i;j] = max (max (abs (xode.[i].[j] - xbase)));
  110.       }
  111.     }
  112.  
  113.     //-----------------------------------------------------------//
  114.  
  115.  
  116.     > results
  117.      results =
  118.      matrix columns 1 thru 6
  119.      1.97e-05   0.000297   0.000634    0.00815      0.078       1.44  
  120.      0.000128   7.89e-05   0.000632    0.00924     0.0732       1.61  
  121.      0.000647   0.000625    0.00112     0.0147     0.0995       1.46  
  122.       0.00355    0.00352    0.00271     0.0118     0.0883      0.862  
  123.        0.0254     0.0254     0.0254      0.104      0.218       1.72  
  124.         0.513      0.513      0.513      0.589      0.467       1.82  
  125.  
  126.  
  127.     Each row of results is a function of the absolute error
  128.     (abserr) and each column is a function of the relative error
  129.     (relerr).
  130.  
  131.  
  132. See Also: ode4
  133.